package com.wrial.kind.linkedList;
/*
 * @Author  Wrial
 * @Date Created in 18:04 2020/8/7
 * @Description
 */

import org.omg.PortableServer.LIFESPAN_POLICY_ID;

public class ReverseList {

    /**
     * 头插
     * headTemp = head.next;
     * temp = dummy.next
     * dummy.next=head
     * head.next= temp
     * head=headTemp;
     */
    public ListNode reverseList(ListNode head) {
        ListNode dummy = new ListNode(-1);

        while (head != null) {
            ListNode nextHead = head.next;
            ListNode temp = dummy.next;
            dummy.next = head;
            head.next = temp;
            head = nextHead;
        }
        return dummy.next;
    }


    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }
}
